
const redis = require('redis');
const _ = require('lodash');
const CJCONFIG = global.CJCONFIG;
const Logger = global.Logger('redis');
const Promise = require('bluebird');

Promise.promisifyAll(redis.RedisClient.prototype);
Promise.promisifyAll(redis.Multi.prototype);

let retry_strategy = ()=> {
    return 1000
};

//  初始化连接redis
_.each(CJCONFIG.redis, (dbConfig, dbname) => {
    dbConfig.retry_strategy = retry_strategy;
    let client = redis.createClient(dbConfig);
    client.on('error', (err) => {
        Logger.error(`redis connect error: ${dbname}`, err);
    });
    client.on('ready', (err) => {
        Logger.info(`redis client ready: ${dbname}`);
    });
    exports[dbname] = client;
});